package com.gethistorics.components;

import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class Utils {
   
   /**
    * Gets an image from the application image folder.
    * 
    * @param name the filename of the image within the images folder
    * 
    * @return the image if it exists, null otherwise
    */
   public static Image getImage(String name) {
      try {
         return ImageIO.read(new File(System.getProperty("user.dir")
               + File.separatorChar + "images" + File.separatorChar + name));
      } catch (IOException e) {
         e.printStackTrace();
         return null;
      }
   }

   /**
    * Gets the icon from the application image folder.
    * 
    * @param name the filename of the image within the images folder
    * 
    * @return the icon
    */
   public static ImageIcon getIcon(String name) {
      return new ImageIcon(System.getProperty("user.dir") + File.separatorChar
            + "images" + File.separatorChar + name);
   }
}
